package utils

import (
	"gin-gateway/core/init"
	"github.com/gomodule/redigo/redis"
)

// redis 执行 pipeline
func RedisPipline(pip ...func(c redis.Conn)) error {
	redisConn, err := Init.RedisConnFactory("default_db")
	if err != nil {
		return err
	}
	defer redisConn.Close()
	for _, f := range pip {
		f(redisConn)
	}
	redisConn.Flush()
	return nil
}

func RedisDo(cmd string, args ...interface{}) (interface{}, error) {
	redisConn, err := Init.RedisConnFactory("default_db")
	if err != nil {
		return nil, err
	}
	defer redisConn.Close()
	return redisConn.Do(cmd, args...)
}
